import React, { useCallback, useEffect, useMemo, useState } from "react";
import { Table, Button, Card, Divider, App, Upload } from "antd";
import { LibAppView } from "../../../../lib";
import { utils } from "elmer-common";
import { TaskRecord } from "./TaskDetail";
import { TaskList } from "./TaskList";
import { Mobile } from "./Mobile";
import { Desktop } from "./Desktop";

const StudentTask = () => {
    const [ showTaskRecord, setShowTaskRecord ] = useState(() => utils.getQuery("page") === "detail");
    const [ currentTask, setCurrentTask ] = useState<string>(() => utils.getQuery("name") ?? "没有任务");
    const gotoViews = useCallback((taskName: string) => {
        setCurrentTask(taskName);
        setShowTaskRecord(true);
    }, []);
    const goBack = useCallback(() => {
        setCurrentTask("");
        setShowTaskRecord(false);
    }, []);
    return (<LibAppView.ScreenMedia Desktop={Desktop} Mobile={Mobile} showBack={showTaskRecord} onBack={goBack}>
        { showTaskRecord && <TaskRecord task={currentTask} goBack={goBack}/> }
        { !showTaskRecord && <TaskList gotoViews={gotoViews}/> }
    </LibAppView.ScreenMedia>);
};

export default StudentTask;